/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.maternity.classes.dao;

import br.com.maternity.classes.entity.Responsavel;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *
 * @author Gattini
 */
public class ResponsavelDAO extends GenericDAO<Responsavel> {
    private static Responsavel instance = new Responsavel();
    public ResponsavelDAO(){
        super(instance);
    }

    @Override
    public List<GenericDAOField> listFields() {
        List l = new ArrayList<GenericDAOField>();

        l.add(new GenericDAOField(
                "Id", "setId", "getId", Integer.class, true, GenericDAOFieldPrimaryKey.IDENTITY));
        l.add(new GenericDAOField(
                "IdAtendimento", "setIdAtendimento", "getIdAtendimento", Integer.class));
        l.add(new GenericDAOField(
                "Nome", "setNome", "getNome", String.class));
        l.add(new GenericDAOField(
                "CPF", "setCpf", "getCpf", String.class));
        l.add(new GenericDAOField(
                "Logradouro", "setLogradouro", "getLogradouro", String.class));
        l.add(new GenericDAOField(
                "Numero", "setNumero", "getNumero", String.class));
        l.add(new GenericDAOField(
                "Complemento", "setComplemento", "getComplemento", String.class));
        l.add(new GenericDAOField(
                "CEP", "setCep", "getCep", String.class));
        l.add(new GenericDAOField(
                "Bairro", "setBairro", "getBairro", String.class));
        l.add(new GenericDAOField(
                "Cidade", "setCidade", "getCidade", String.class));
        l.add(new GenericDAOField(
                "UF", "setUf", "getUf", String.class));

        return l;
    }

    @Override
    public String tableName() {
        return "Responsavel";
    }
    
    public Responsavel getByAtendimento(Integer idAtendimento){
        try{
            String query = "SELECT * FROM " + tableName() + " WHERE IdAtendimento = ?";
            PreparedStatement ps = super.getPreparedStatement(query);
            ps.setInt(1, idAtendimento);
            return super.select(ps);
        }
        catch(Exception ex){
            return null;
        }
    }
    
}
